<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'收款单'),
	array('op'=>'edit','title'=>'添加收款'),
);
$return['statuss']=$this->infee_status;
$return['paytype']=get_pay_types();
$return['paytype']['peerpay']='找人代付';
$return['paytype']['offpay']='线下收款';
$return['paytype']['offsao']='线下扫码';
$return['ispay']=array('0'=>'未支付_No pay','1'=>'已支付_Is pay');
$shoutypes=$this->setting['shoutypes']?:array(array('name'=>'','title'=>'默认'));
$return['shoutypes']=array();
foreach($shoutypes as $tv){
	$return['shoutypes'][$tv['name']]=$tv['title'];
}
$zhanghutypes=$this->setting['zhanghutypes']?:array();
$return['zhanghutypes']=array();
foreach($zhanghutypes as $tv){
	$return['zhanghutypes'][$tv['name']]=$tv['title'];
}
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['paytype'])){
		$params['paytype']=$_RQ['paytype'];
		$return['params']['paytype']=$_RQ['paytype'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_erp_infee',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'paytype','title'=>'结算方式','type'=>'radio','options'=>'paytype'),
			array('name'=>'codesn','title'=>'收款账户','type'=>'radio','options'=>'zhanghutypes'),
			array('name'=>'fee','title'=>'收款金额','type'=>'string'),
			array('name'=>'type','title'=>'收入类型','type'=>'radio','options'=>'shoutypes'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'paytype','width'=>10,'title'=>'结算方式','type'=>'radio','options'=>'paytype'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$data=array(
			'paytype'=>trim($post['paytype']),
			'codesn'=>trim($post['codesn']),
			'fee'=>trim($post['fee']),
			'type'=>trim($post['type']),
			'remark'=>trim($post['remark']),
		);
		if(!$id){
			$data['uniacid']=$_SESSION['uniacid'];
			$data['createtime']=time();
			pdo_insert('jy_erp_infee',$data);
		}else{
			pdo_update('jy_erp_infee',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
		exi('操作成功！','','list');
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_erp_infee',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'desc'=>'收款单',
		'edit'=>array(
			array('name'=>'paytype','title'=>'结算方式','type'=>'radio','options'=>'paytype'),
			array('name'=>'codesn','title'=>'收款账户','type'=>'radio','options'=>'zhanghutypes'),
			array('name'=>'fee','title'=>'收款金额','type'=>'string'),
			array('name'=>'type','title'=>'收入类型','type'=>'radio','options'=>'shoutypes','help'=>'先设置：基础信息--收付信息--收入类型'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_erp_infee',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
